/*
 * Copyright (c) 2006-2020, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-09     RT-Thread    first version
 */
#include <rtthread.h>
#include <board.h>
#include <rtdevice.h>

#define DBG_TAG         "main"
#define DBG_LVL         DBG_LOG
#include <rtdbg.h>


/* PLEASE DEFINE the LED0 pin for your board, such as: PA5 */
#define LED0_PIN    GET_PIN(E, 5)
#define LED1_PIN    GET_PIN(E, 6)

int main(void)
{
    int count = 3;

    /* set LED0 pin mode to output */
    rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
    rt_pin_mode(LED1_PIN, PIN_MODE_OUTPUT);
//    rt_fota_start_application();
    while (++count)
    {
        /* set LED0 pin level to high or low */
        rt_pin_write(LED0_PIN, count % 2);
        rt_pin_write(LED1_PIN, (count + 1) % 2);
//        LOG_D("Hello RT-Thread!");
        rt_thread_mdelay(100);
    }
}

int read_reg(void)
{
    struct rt_qspi_device * device = (struct rt_qspi_device *)rt_device_find("norspi");

    if(device != RT_NULL)
    {
        rt_uint8_t read_reg[3] = {0x05, 0x35, 0x15};
        rt_uint8_t reg[3] = {0};
//        rt_uint8_t we = 0x06;
//        rt_uint8_t send[3] = {0x01, 0x00, 0x00};
//
//        rt_qspi_send(device, &we, 1);
//        rt_qspi_send(device, send, sizeof(send));

        for(rt_uint8_t i = 0;i < 3;i ++)
            rt_qspi_send_then_recv(device, &read_reg[i], 1, &reg[i], 1);
        LOG_I("REG:\t0x%02X\t0x%02X\t0x%02X",reg[0], reg[1], reg[2]);
    }
    return 0;
}
MSH_CMD_EXPORT(read_reg,read w25q64 reg);
